package ncku.account.gui.old;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ncku.account.event.Launcher;
import ncku.account.gui.newTransaction;

public class categoryFunction {
    JFrame frame = new JFrame ("類別編輯視窗");
    
    public categoryFunction(String name) {
    	frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add (BorderLayout.CENTER,new Configuration(name));
        frame.pack();
        frame.setLocation(300, 150);
        frame.setSize(400,200);
        frame.setVisible (true);
    }
        
   class Configuration extends JPanel {
    	private JLabel JLname;
	    private JButton JBSubmit;
	    private JButton JBCancel;
	    private JTextField inputName;
	    
    	public Configuration(String name){
    		//construct components
	    	JLname = new JLabel ("Category Name:");
	        JBSubmit = new JButton ("Submit");
	        JBCancel = new JButton ("Cancel");
	        inputName = new JTextField(10);
	        
	        
	        //adjust size and set layout
	        setPreferredSize (new Dimension (681, 422));
	        setLayout (null);
	        
	        //按下Submit後的Listener(new Category)
	        JBSubmit.addActionListener(new ActionListener() { 
			public void actionPerformed(ActionEvent e) 
			{ 
				String inputCategoryName = inputName.getText();
				//newTransaction.result.add(inputCategoryName);
				Launcher.frame.getContentPane().remove(1);
				Launcher.frame.getContentPane().add (BorderLayout.CENTER,new newTransaction());
				Launcher.frame.getContentPane().doLayout();
				frame.dispose();
			}}); 
	        
	        //按下Cancel後的Listener
	        JBCancel.addActionListener(new ActionListener() { 
			public void actionPerformed(ActionEvent e) 
			{ 
				frame.dispose();
			}}); 
	        

	        //add components	       
	        add (JLname);
	        add (JBSubmit);
	        add (JBCancel);
	        add (inputName);
	       
	        //set component bounds (only needed by Absolute Positioning)	       
	        JLname.setBounds (25, 35, 100, 25);
	        JBSubmit.setBounds (65, 100, 80, 30);
	        JBCancel.setBounds (160, 100, 80, 30);
	        inputName.setBounds (130, 35, 150, 25);        
    }
   }
}
